package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ErrorCode;
import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.domain.SuccessCode;
import com.atguigu.jxc.entity.Customer;
import com.atguigu.jxc.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/customer")
public class CustomerController {
    @Autowired
    private CustomerService customerService;

    //第五个接口 客户列表分页展示
    @PostMapping("/list")
    public Map<String,Object> list(Integer page, Integer rows, String  customerName){
       return customerService.list(page,rows,customerName);
    }
    //客户添加或修改
    @PostMapping("/save")
    public ServiceVO saveOrUpdate(Customer customer){
        Boolean result= customerService.saveOrUpdate(customer);

        if(result){
            return new ServiceVO(SuccessCode.SUCCESS_CODE,SuccessCode.SUCCESS_MESS);
        }
        return new ServiceVO(ErrorCode.REQ_ERROR_CODE,ErrorCode.REQ_ERROR_MESS);

    }

    //客户删除（支持批量删除）
    @PostMapping("/delete")
    public ServiceVO delete(String ids){
        Boolean result=customerService.delete(ids);
        if(result){
            return new ServiceVO(SuccessCode.SUCCESS_CODE,SuccessCode.SUCCESS_MESS);
        }
        return new ServiceVO(ErrorCode.REQ_ERROR_CODE,ErrorCode.REQ_ERROR_MESS);
    }






}
